<?php

/*
 * |--------------------------------------------------------------------------
 * | Web Routes
 * |--------------------------------------------------------------------------
 * |
 * | Here is where you can register web routes for your application. These
 * | routes are loaded by the RouteServiceProvider within a group which
 * | contains the "web" middleware group. Now create something great!
 * |
 */
// /
Route::get ( '/', function () {
	return view ( 'welcome' );
} );

// /photo/index
Route::get ( '/photo/index', 'PhotoController@index' );

// /foo
Route::any ( 'foo', function () {
	return 'Hello World!';
} );

// /here
Route::permanentRedirect ( '/here', '/there' );

// /there
Route::get ( 'there', function () {
	return 'this is there';
} );

// /user/100
Route::get ( 'user/{id}', function ($id) {
	return 'User ' . $id;
} )->where ( 'id', '[0-9]+' );

// /posts/12/comments/100
Route::get ( 'posts/{post}/comments/{comment}', function ($postId, $commentId) {
	return 'postId：' . $postId . '&commentId：' . $commentId;
} )->where ( [ 
		'id' => '[0-9]+',
		'comment' => '[0-9]+' 
] );

// /user/Tom
Route::get ( 'username/{name?}', function ($name = 'Jack') {
	return $name;
} )->where ( 'name', '[A-Za-z]+' );

//middleware
Route::middleware ( [ 'web'] )->group ( function () {
	Route::get ( '/m1', function () {
		// 使用 first 和 second 中间件
		return 'm1';
	} );
	
	Route::get ( '/m2', function () {
		// 使用 first 和 second 中间件
		return 'm2';
	} );
} );
